package com.qf.test;

import com.qf.mapper.UserMapper;
import com.qf.pojo.TbUser;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by 田贵宾 on 2022/8/23 12:08
 *
 * @author 田贵宾
 * @version 1.0
 * //TODO java练习阶段
 * @since 1.0
 */
public class testMain {
    /**
     * 测试方法，必须是public  void  不能有参数
     */
    @Test
    public void testSimpleQuery() throws IOException {
        //使用mybatis
            //加载配置文件
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
        //通过这个配置文件得内容创建数据库得会话工厂
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resourceAsStream);
        //创建接口对象
        SqlSession sqlSession = build.openSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        TbUser userById = mapper.findUserById(3L);
        System.out.println(userById);
        sqlSession.close();
        //执行方法
    }
}
